package com.vancouver.knows.business.service.impl;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.pangu.util.StringUtil;
import com.vancouver.knows.business.bean.UserInfo;

/**
 * 用户信息列表解析
 * Created by llf
 */
public class UserInfoHandler extends ACheckableJsonParser{
	private UserInfo userInfo = null;
	@Override
	protected void parserContent(JSONObject content) throws Exception {
		//String posts = content.getString("user_info");
		//userInfo = JSON.parseObject(posts, UserInfo.class);
		JSONObject jsonPostResult = content.getJSONObject("user_info");
		userInfo = new UserInfo();
		if (jsonPostResult != null) {
			//===========用户信息===========
			userInfo.setUserID(jsonPostResult.getString("user_id"));
			userInfo.setLogin(jsonPostResult.getString("user_login"));
			userInfo.setEmail(jsonPostResult.getString("user_email"));
			userInfo.setName(jsonPostResult.getString("display_name"));
			userInfo.setAvatar(jsonPostResult.getString("user_avatar"));
			userInfo.setRegisterDate(jsonPostResult.getString("register_date"));
			String registerType = jsonPostResult.getString("register_type");
			if (!StringUtil.isEmptyString(registerType)) {
				userInfo.setRegisterType(JSON.parseObject(registerType, UserInfo.RegisterType.class));
			}
			String userMeta = jsonPostResult.getString("user_meta");
			if (!StringUtil.isEmptyString(userMeta)) {
				userInfo.setUserMeta(JSON.parseObject(userMeta, UserInfo.UserMeta.class));
			}
			userInfo.setTotalUnReadPostComment(jsonPostResult.getString("total_unread_post_comment"));
			userInfo.setTotalUnReadComment(jsonPostResult.getString("total_unread_comment"));
			//============积分详情信息=================
			JSONObject pointsDetailObj = jsonPostResult.getJSONObject("user_points_detail");
			userInfo.userPointsDetailsInfo.setCommentPoints(pointsDetailObj.getString("comment_points"));
			userInfo.userPointsDetailsInfo.setCommentUpvotePoints(pointsDetailObj.getString("comment_upvote_points"));
			userInfo.userPointsDetailsInfo.setPointsPolicy(pointsDetailObj.getString("points_policy"));
			userInfo.userPointsDetailsInfo.setPointsStore(pointsDetailObj.getString("points_store"));
			userInfo.userPointsDetailsInfo.setPostPoints(pointsDetailObj.getString("post_points"));
			userInfo.userPointsDetailsInfo.setPostUpvotePoints(pointsDetailObj.getString("post_upvote_points"));
			userInfo.userPointsDetailsInfo.setRedeemedPoints(pointsDetailObj.getString("redeemed_points"));
			userInfo.userPointsDetailsInfo.setTotalPoints(pointsDetailObj.getString("total_points"));
			userInfo.userPointsDetailsInfo.setUpvotePoints(pointsDetailObj.getString("upvote_points"));
			userInfo.userPointsDetailsInfo.setImageSharePoints(pointsDetailObj.getString("image_share_points"));
		}
		
	}
	public UserInfo getUserInfo(){
		return userInfo;
	}
	
}
